package com.jichangxiu.common.exception;

import com.jichangxiu.common.constant.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * ServerException:
 *
 * @author Jcx
 * @create 2023-04-03 21:49
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ServerException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private String code;

    private String msg;

    public static ServerException build() {
        return new ServerException(ErrorCode.INTERNAL_SERVER_ERROR.getMsg());
    }

    public static ServerException build(String msg) {
        return new ServerException(msg);
    }

    public static ServerException build(String msg, Throwable e) {
        return new ServerException(msg, e);
    }

    public ServerException(String msg) {
        super(msg);
        this.code = ErrorCode.INTERNAL_SERVER_ERROR.getCode();
        this.msg = msg;
    }

    public ServerException(ErrorCode errorCode) {
        super(errorCode.getMsg());
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
    }

    public ServerException(String msg, Throwable e) {
        super(msg, e);
        this.code = ErrorCode.INTERNAL_SERVER_ERROR.getCode();
        this.msg = msg;
    }

}
